package com.example.boot.dluseraddress.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.tomcat.jni.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.boot.dluseraddress.dao.DlUserAddressMapper;
import com.example.boot.dluseraddress.model.DlUserAddress;
import com.example.boot.dluseraddress.service.DlUserAddressService;
import com.example.boot.util.JSONToObj;
import com.example.boot.util.NewUUID;

@Service
public class DlUserAddressImpl implements DlUserAddressService {
	@Autowired
	private DlUserAddressMapper dlUserAddressMapper;

	@Transactional
	@Override
	public Boolean saveAddress(String addressDetail) throws Exception {
		String uuid = NewUUID.UUID();
		JSONToObj jo = new JSONToObj();
		DlUserAddress address = (DlUserAddress) jo.JsonToClass(addressDetail, DlUserAddress.class);
		address.setCreateDate(new Date());
		address.setId(uuid);
		address.setUpdateDate(new Date());
		return dlUserAddressMapper.insertSelective(address) == 1 ? true : false;
	}

	@Transactional
	@Override
	public List<Address> byOpenIdFinAllAddress(String openId) throws Exception {

		return dlUserAddressMapper.byOpenIdFinAllAddress(openId);
	}

}
